<?php

namespace App\Http\Controllers\Api\V1\Site;

use Illuminate\Http\Request;
use Biz\Jobs\SiteEmailSendJob;
use Biz\Services\Site\SitePaperAbstractService;
use Biz\Requests\Site\StorePaperAbstractRequest;
use Biz\Mailers\Site\SitePaperAbstractPassedMail;
use Biz\Mailers\Site\SitePaperAbstractRefuseMail;
use Biz\Mailers\Site\SitePaperAbstractReviewMail;
use Biz\Mailers\Site\SitePaperAbstractReviseMail;
use Biz\Requests\Site\UpdatePaperAbstractRequest;
use Biz\Resources\Site\SitePaperAbstractResource;
use Lumen\Http\Resources\Json\DataResourceResponse;
use Laravel\Lumen\Routing\Controller as BaseController;
use Biz\Resources\Site\SitePaperAbstractResourceCollection;

/**
 * PaperAbstractController.
 *
 * @license [http://www.85do.com] [杭州永奥网络科技有限公司]
 * @copyright Copyright (c) 2018-2026 Hangzhou Yongao Technology Co., Ltd. All rights reserved.
 */
class PaperAbstractController extends BaseController
{
    /**
     * @var mixed
     */
    protected $service;

    /**
     * PaperAbstractController constructor.
     *
     * @param SitePaperAbstractService $service
     */
    public function __construct(SitePaperAbstractService $service)
    {
        $this->service = $service;
    }

    /**
     * Display a listing of the resource.
     *
     * @param Request $request
     * @param string  $paper_id
     *
     * @return SitePaperAbstractResourceCollection
     */
    public function index(Request $request, string $paper_id)
    {
        $results = $this->service->index($request, $paper_id);

        return new SitePaperAbstractResourceCollection($results);
    }

    /**
     * Store a newly created resource in storage.
     *
     * @param StorePaperAbstractRequest $request
     * @param string                    $paper_id
     *
     * @return \Illuminate\Http\Response
     */
    public function store(StorePaperAbstractRequest $request, string $paper_id)
    {
        $paperAbstract = $this->service->store($request, $paper_id);

        return new SitePaperAbstractResource($paperAbstract);
    }

    /**
     * Display the specified resource.
     *
     * @param string $paper_id
     * @param string $abstract_id
     *
     * @return \Illuminate\Http\Response
     */
    public function show(string $paper_id, string $abstract_id)
    {
        $paperAbstract = $this->service->show($paper_id, $abstract_id);

        return new SitePaperAbstractResource($paperAbstract);
    }

    /**
     * Update the specified resource in storage.
     *
     * @param UpdatePaperAbstractRequest $request
     * @param string                     $paper_id
     * @param string                     $abstract_id
     *
     * @return \Illuminate\Http\Response
     */
    public function update(UpdatePaperAbstractRequest $request, string $paper_id, string $abstract_id)
    {
        $paperAbstract = $this->service->edit($paper_id, $abstract_id, $request->all());

        return new SitePaperAbstractResource($paperAbstract);
    }

    /**
     * Remove the specified resource from storage.
     *
     * @param string $paper_id
     * @param string $abstract_id
     *
     * @return \Illuminate\Http\Response
     */
    public function destroy(string $paper_id, string $abstract_id)
    {
        $result = $this->service->remove($paper_id, $abstract_id);

        return new DataResourceResponse($result);
    }

    /**
     * Review.
     *
     * @param string $paper_id
     * @param string $abstract_id
     *
     * @return \Illuminate\Http\Response
     */
    public function review(string $paper_id, string $abstract_id)
    {
        $paperAbstract = $this->service->review($paper_id, $abstract_id);

        // Send email
        $mail = new SitePaperAbstractReviewMail($paperAbstract);
        dispatch(new SiteEmailSendJob($mail));

        return new SitePaperAbstractResource($paperAbstract);
    }

    /**
     * Passed.
     *
     * @param string $paper_id
     * @param string $abstract_id
     *
     * @return \Illuminate\Http\Response
     */
    public function passed(string $paper_id, string $abstract_id)
    {
        $paperAbstract = $this->service->passed($paper_id, $abstract_id);

        // Send email
        $mail = new SitePaperAbstractPassedMail($paperAbstract);
        dispatch(new SiteEmailSendJob($mail));

        return new SitePaperAbstractResource($paperAbstract);
    }

    /**
     * Refuse.
     *
     * @param string $paper_id
     * @param string $abstract_id
     *
     * @return \Illuminate\Http\Response
     */
    public function refuse(string $paper_id, string $abstract_id)
    {
        $paperAbstract = $this->service->refuse($paper_id, $abstract_id);

        // Send email
        $mail = new SitePaperAbstractRefuseMail($paperAbstract);
        dispatch(new SiteEmailSendJob($mail));

        return new SitePaperAbstractResource($paperAbstract);
    }

    /**
     * Revise.
     *
     * @param string $paper_id
     * @param string $abstract_id
     *
     * @return \Illuminate\Http\Response
     */
    public function revise(string $paper_id, string $abstract_id)
    {
        $paperAbstract = $this->service->revise($paper_id, $abstract_id);

        // Send email
        $mail = new SitePaperAbstractReviseMail($paperAbstract);
        dispatch(new SiteEmailSendJob($mail));

        return new SitePaperAbstractResource($paperAbstract);
    }
}
